<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Test Web worker</title>
    <script type="text/JavaScript">
        function init(){
            var worker = new Worker('compute.js');
            //event 参数中有 data 属性，就是子线程中返回的结果数据
            worker.onmessage= function (event) {
                // 把子线程返回的结果添加到 div 上
                document.getElementById("result").innerHTML +=
                    event.data+"<br/>";
            };
        }
    </script>
</head>
<body onload="init()">
<div id="result"></div>
</body>
</html>
